package com.ti.shangou.controller;

import org.springframework.boot.autoconfigure.couchbase.CouchbaseProperties;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.Scanner;

/**
 * 作者：田宝山
 * 日期：2020/6/4
 */
@Controller
public class ImgController {

//    @RequestMapping("/upload/{path}")
    @ResponseBody
    public Object showImg(HttpServletRequest request, HttpServletResponse response, @PathVariable("path") String pahtName) throws Exception {
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(new File("F:/upload/"+pahtName)));
        BufferedOutputStream bos = new BufferedOutputStream(response.getOutputStream());
        byte[] arr =new  byte[1024*1024*5];
        int len =0;
        while ((len = bis.read(arr))!=-1){
            bos.write(arr,0,len);
        }
        bos.flush();
        bos.close();
        return 0;
    }


}
